/**@file: 状态管理文件 */
import {
	reqGetMenuList
} from '@/api';
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
	state: {
		avatar: localStorage.getItem('avatar') || '',
		menus: []
	},
	mutations: {
		changeAvatar(state, newVal) {
			state.avatar = newVal;
		},
		SET_MENUS: (state, menus) => {
			state.menus = menus;
		}
	},
	actions: {
		getMenus({
			commit
		}) {
			return new Promise(async (resolve) => {
				const {
					data
				} = await reqGetMenuList({});
				console.log(data);
				commit('SET_MENUS', data);
				resolve();
			})
		}
	},
	modules: {

	}
});
